package com.fang.blogsystem.controller;

import com.fang.blogsystem.mapper.StatisticMapper;
import com.fang.blogsystem.result.StaticticsBo;
import com.fang.blogsystem.utils.MailUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.xml.soap.SAAJResult;

/**
 * @author Bernie_fang
 * @create 2021/6/4 14:43
 **/
@Component
public class ScheduleTask {

    @Autowired
    private StatisticMapper statisticMapper;

    @Autowired
    private MailUtils mailUtils;

    @Value("${spring.mail.username}")
    private String mailto;

    //每月1号中午12点发送邮件
    @Scheduled(cron = "0 0 12 1 * ?")
    public void  sendMail(){
        long totalVisit = statisticMapper.getTotalVisit();
        long totalComment = statisticMapper.getTotalComment();
        StringBuffer content = new StringBuffer();
        content.append("博客系统的总访问量为：" + totalVisit + "人次").append("\n");
        content.append("博客系统的总评论量为：" + totalComment + "人次").append("\n");
        mailUtils.sendSimpleEmail(mailto,"个人博客系统流量统计情况", content.toString());
    }

}
